package com.elephant.core.event;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;

/**
 * @Author: hai
 * @Date: 2019/1/3 10:38
 */
@Service
public class UserRegisterService implements ApplicationEventPublisherAware {

    private ApplicationEventPublisher applicationEventPublisher;

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }

    public boolean register(User user){
        //用户注册
        System.out.println("service用户" + user + "注册成功");

        //消息发布
        applicationEventPublisher.publishEvent(new UserRegisterEvent(this, user));
        return true;
    }
}
